using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using JSON;

public class JSONItem{
	#region 单例
	private static JSONItem instance;
	public static JSONItem getInstance(){
	if (instance == null)
		instance = new JSONItem ();
		return instance;
	}
	#endregion

	#region 变量
	private JSONNode json;
	private JSONNode JSONData{
		get{
			if(json == null)
				json = JsonRead.Read("JSONItem");
			return json;
		}
	}
	#endregion
	#region 外部调用
	public void Clear(){
		json = null;
	}
	public JSONNode GetJSON(string key){
		return JSONData [key];
	}
	public JSONNode GetJSON(int index){
		return JSONData [index];
	}
	/// <summary>
	/// 有多少个数据
	/// </summary>
	public int GetCount(){
	return JSONData.Count;
	}

    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListID(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetID(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 物品ID (_1.物品ID由5位数组成，从小到大排列_2.千位数表示物品类型，超过10时万位加1_3.装备的百位数表示品质_4.技能、怪物、BOSS的个位数表示阶级，十位数表示不同种类，超过10时向百位进1) 
	/// </summary>
	public int GetID(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["ID"].AsInt;
		return  value;
	}
	/// <summary>
	/// 物品ID (_1.物品ID由5位数组成，从小到大排列_2.千位数表示物品类型，超过10时万位加1_3.装备的百位数表示品质_4.技能、怪物、BOSS的个位数表示阶级，十位数表示不同种类，超过10时向百位进1)  :From Index
	/// </summary>
	public int GetID(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetID(index.ToString());
			return  value;
		}
		value = json["ID"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListName(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetName(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 物品名称
	/// </summary>
	public string GetName(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["Name"].ToString();
		return  value;
	}
	/// <summary>
	/// 物品名称 :From Index
	/// </summary>
	public string GetName(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetName(index.ToString());
			return  value;
		}
		value = json["Name"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListType(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetType(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 物品类型 (_1.货币（金币、钻石、活动代币、符文碎片)_2.武器_3.胸甲_4.头盔_5.时装_6.技能卡_7.怪物卡_8.BOSS卡_9.符文_10.宝箱_61.手势1 _62.手势2_63.手势3 _64.手势4) 
	/// </summary>
	public int GetType(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Type"].AsInt;
		return  value;
	}
	/// <summary>
	/// 物品类型 (_1.货币（金币、钻石、活动代币、符文碎片)_2.武器_3.胸甲_4.头盔_5.时装_6.技能卡_7.怪物卡_8.BOSS卡_9.符文_10.宝箱_61.手势1 _62.手势2_63.手势3 _64.手势4)  :From Index
	/// </summary>
	public int GetType(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetType(index.ToString());
			return  value;
		}
		value = json["Type"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListQuality(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetQuality(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 品质 ((Quality_1.普通Quality_2.稀有Quality_3.史诗Quality_4.传说)) 
	/// </summary>
	public int GetQuality(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Quality"].AsInt;
		return  value;
	}
	/// <summary>
	/// 品质 ((Quality_1.普通Quality_2.稀有Quality_3.史诗Quality_4.传说))  :From Index
	/// </summary>
	public int GetQuality(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetQuality(index.ToString());
			return  value;
		}
		value = json["Quality"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListLv(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetLv(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 初始等级
	/// </summary>
	public int GetLv(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Lv"].AsInt;
		return  value;
	}
	/// <summary>
	/// 初始等级 :From Index
	/// </summary>
	public int GetLv(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetLv(index.ToString());
			return  value;
		}
		value = json["Lv"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListLvMax(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetLvMax(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 等级上限
	/// </summary>
	public int GetLvMax(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["LvMax"].AsInt;
		return  value;
	}
	/// <summary>
	/// 等级上限 :From Index
	/// </summary>
	public int GetLvMax(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetLvMax(index.ToString());
			return  value;
		}
		value = json["LvMax"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListFlod(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetFlod(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 叠加上限
	/// </summary>
	public int GetFlod(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Flod"].AsInt;
		return  value;
	}
	/// <summary>
	/// 叠加上限 :From Index
	/// </summary>
	public int GetFlod(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetFlod(index.ToString());
			return  value;
		}
		value = json["Flod"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListSale(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetSale(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 出售价格
	/// </summary>
	public int GetSale(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Sale"].AsInt;
		return  value;
	}
	/// <summary>
	/// 出售价格 :From Index
	/// </summary>
	public int GetSale(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetSale(index.ToString());
			return  value;
		}
		value = json["Sale"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListIcon(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetIcon(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 物品图标
	/// </summary>
	public string GetIcon(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["Icon"].ToString();
		return  value;
	}
	/// <summary>
	/// 物品图标 :From Index
	/// </summary>
	public string GetIcon(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetIcon(index.ToString());
			return  value;
		}
		value = json["Icon"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListInfo(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetInfo(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 物品描述
	/// </summary>
	public string GetInfo(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["Info"].ToString();
		return  value;
	}
	/// <summary>
	/// 物品描述 :From Index
	/// </summary>
	public string GetInfo(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetInfo(index.ToString());
			return  value;
		}
		value = json["Info"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListPrefabId(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetPrefabId(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 游戏内对应创建物ID
	/// </summary>
	public int GetPrefabId(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["PrefabId"].AsInt;
		return  value;
	}
	/// <summary>
	/// 游戏内对应创建物ID :From Index
	/// </summary>
	public int GetPrefabId(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetPrefabId(index.ToString());
			return  value;
		}
		value = json["PrefabId"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListMap(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetMap(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 映射
	/// </summary>
	public string GetMap(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["Map"].ToString();
		return  value;
	}
	/// <summary>
	/// 映射 :From Index
	/// </summary>
	public string GetMap(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetMap(index.ToString());
			return  value;
		}
		value = json["Map"].ToString();
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListElement(int target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetElement(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 元素 ((1：电；2：光；3：水；4：火；5：石；6：暗；)) 
	/// </summary>
	public int GetElement(string key){
		JSONNode json = GetJSON (key);
		int  value;
		value = json["Element"].AsInt;
		return  value;
	}
	/// <summary>
	/// 元素 ((1：电；2：光；3：水；4：火；5：石；6：暗；))  :From Index
	/// </summary>
	public int GetElement(int index){
		int value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetElement(index.ToString());
			return  value;
		}
		value = json["Element"].AsInt;
		return  value;
	}
    /// <summary>
	/// GetJSONNodeList Like Target
	/// </summary>
	public int[] GetListSource(string target){
		List<int> list = new List<int>();
		for (int i = 0; i < GetCount(); i++) {
			if( GetSource(i) == target)
				list.Add(i);
		}
		return list.ToArray();
	}
	/// <summary>
	/// 获得来源
	/// </summary>
	public string GetSource(string key){
		JSONNode json = GetJSON (key);
		string  value;
		value = json["Source"].ToString();
		return  value;
	}
	/// <summary>
	/// 获得来源 :From Index
	/// </summary>
	public string GetSource(int index){
		string value;
		JSONNode json = GetJSON (index);
		if(json == null){
			value = GetSource(index.ToString());
			return  value;
		}
		value = json["Source"].ToString();
		return  value;
	}

	#endregion
}